import React from "react";
import { Button, Checkbox, Form, Input, Select } from "antd";
import { request } from "../../utils/request";
import { useNavigate } from "react-router-dom";

const onFinishFailed = (errorInfo: any) => {
  console.log("Failed:", errorInfo);
};

// 添加接口
const addList = async (data: { username: string; role: string }) => {
  return await request.put("/user/list", data);
};
const App: React.FC = () => {
  const navigate = useNavigate()
  const onFinish = (values: any) => {
    addList(values).then(() => {
      navigate('/list/manage')
    });
  };

  return (
    <Form
      name="basic"
      labelCol={{ span: 8 }}
      wrapperCol={{ span: 16 }}
      style={{ maxWidth: 600 }}
      initialValues={{ remember: true }}
      onFinish={onFinish}
      onFinishFailed={onFinishFailed}
      autoComplete="off"
    >
      <Form.Item
        label="Username"
        name="username"
        rules={[{ required: true, message: "Please input your username!" }]}
      >
        <Input />
      </Form.Item>

      <Form.Item label="Select" name="role">
        <Select>
          <Select.Option value="admin">admin</Select.Option>
          <Select.Option value="user">user</Select.Option>
        </Select>
      </Form.Item>
      <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
        <Button type="primary" htmlType="submit">
          Submit
        </Button>
      </Form.Item>
    </Form>
  );
};

export default App;
